package com.cmcc.passenger.ui.order

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.cmcc.passenger.data.AppRequest
import com.cmcc.passenger.data.entity.response.OrderRecordResponse
import com.cmcc.shared.utils.L
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MyOrderViewModel : ViewModel() {

    val orderRecords = MutableLiveData<OrderRecordResponse>()

    fun getOrderRecords(page: Int, pageSize: Int) {
        viewModelScope.launch(Dispatchers.Main) {
            try {
                val response = AppRequest.getInstance().getOrders(page, pageSize)
                if (response.isSuccessful) {
                    val data = response.body()
                    orderRecords.value = data?.data
                }
            } catch (e: Exception) {
                L.d("e :" + e.message + "," + e.cause)
            }
        }
    }

}